<?php

namespace JLPay\Models\Trans\Common;

use JLPay\Models\BaseResponse;

/**
 * 获取OpenID响应模型
 */
class GetOpenidResponse extends BaseResponse
{
    /**
     * @var string|null OpenID
     */
    protected ?string $openid = null;

    /**
     * @var string|null 用户标识
     */
    protected ?string $subOpenid = null;

    /**
     * 构造函数
     *
     * @param array|null $responseArray 响应数组
     */
    public function __construct(?array $responseArray = null)
    {
        parent::__construct($responseArray);

        if ($responseArray) {
            $this->openid = $responseArray['openid'] ?? null;
            $this->subOpenid = $responseArray['sub_openid'] ?? null;
        }
    }

    /**
     * 设置OpenID
     *
     * @param string $openid OpenID
     * @return $this
     */
    public function setOpenid(string $openid): self
    {
        $this->openid = $openid;
        return $this;
    }

    /**
     * 获取OpenID
     *
     * @return string|null OpenID
     */
    public function getOpenid(): ?string
    {
        return $this->openid;
    }

    /**
     * 设置用户标识
     *
     * @param string $subOpenid 用户标识
     * @return $this
     */
    public function setSubOpenid(string $subOpenid): self
    {
        $this->subOpenid = $subOpenid;
        return $this;
    }

    /**
     * 获取用户标识
     *
     * @return string|null 用户标识
     */
    public function getSubOpenid(): ?string
    {
        return $this->subOpenid;
    }

    /**
     * 转换为数组格式
     *
     * @return array 数组格式的数据
     */
    public function toArray(): array
    {
        $data = parent::toArray();
        $data = array_merge($data, [
            'openid' => $this->openid,
            'sub_openid' => $this->subOpenid
        ]);

        return $data;
    }
} 